package UserInterface;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.text.MaskFormatter;

public class PutMoneyToPayPhone extends JPanel{
	private JButton btnBack = new JButton("<<Back");
	private JFormattedTextField textFieldAmount;
	MaskFormatter formatter;
    public void putAmount(String amount){
    	textFieldAmount.setText(amount);
    }
	
	
		String s="";
		private NumberPanel panelNumbers =  new NumberPanel();
		private EditorsPanel panelEditors = new EditorsPanel();
		public void putNumbers(){
			JButton[] buttons =panelNumbers.getButtons();
			for(int i=0;i<buttons.length;i++){
				buttons[i].addActionListener(new Listen(buttons[i].getText()));
			}
		}
		class Listen implements ActionListener{
			String text="";
			Listen(String text){
				this.text=text;
			}

			@Override
			public void actionPerformed(ActionEvent e) {
				s+=text;
				textFieldAmount.setText(s);
				
			}

			
			
		}
		
		public void clearS(){
			s="";
		}
		public void setS(String s){
			this.s=s;
			textFieldAmount.setText(s);
		}
		public String getS(){
			return s;
		}
		/**
		 * Create the panel.
		 */
		public void putNumbersListener(ActionListener list){
			panelNumbers.addActionListener(list);
		}
		public void putAcountNumber(String number){
			textFieldAmount.setText(number);
		}
		
		

	String getAcountNumber(){
		return textFieldAmount.getText();
	}
	
	public void putListenerBack(ActionListener list){
		btnBack.addActionListener(list);
	}
	
	public void putListenerOk(ActionListener list){
		panelEditors.setOkListener(list);
	}
	public void putListenerCancel(ActionListener list){
		panelEditors.setCancelListener(list);
	}
	public void putListenerChange(ActionListener list){
		panelEditors.setChangeListener(list);
	}

	/**
	 * Create the panel.
	 */
	public PutMoneyToPayPhone() {
		setBackground(new Color(255, 248, 220));
		this.setSize(500, 500);
		
		JLabel lblEnterAmount = new JLabel("Enter  amount to transfer :");
		lblEnterAmount.setForeground(new Color(128, 0, 0));
		lblEnterAmount.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 18));
		
	
			
			try {
				textFieldAmount = new JFormattedTextField(new MaskFormatter("#############"));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			textFieldAmount.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 14));
			textFieldAmount.setColumns(10);
			
		
		
		 panelNumbers = new NumberPanel();
		
		 panelEditors = new EditorsPanel();
		 JButton btnBack = new JButton("<<Back");
			btnBack.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
			btnBack.setForeground(new Color(128, 0, 0));
			GroupLayout groupLayout = new GroupLayout(this);
			groupLayout.setHorizontalGroup(
				groupLayout.createParallelGroup(Alignment.LEADING)
					.addGroup(groupLayout.createSequentialGroup()
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
							.addGroup(groupLayout.createSequentialGroup()
								.addGap(142)
								.addComponent(lblEnterAmount))
							.addGroup(groupLayout.createSequentialGroup()
								.addGap(114)
								.addComponent(textFieldAmount, GroupLayout.PREFERRED_SIZE, 256, GroupLayout.PREFERRED_SIZE))
							.addGroup(groupLayout.createSequentialGroup()
								.addGap(48)
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
									.addComponent(btnBack, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
									.addGroup(groupLayout.createSequentialGroup()
										.addComponent(panelNumbers, GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE)
										.addGap(30)
										.addComponent(panelEditors, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)))))
						.addContainerGap(43, Short.MAX_VALUE))
			);
			groupLayout.setVerticalGroup(
				groupLayout.createParallelGroup(Alignment.LEADING)
					.addGroup(groupLayout.createSequentialGroup()
						.addGap(66)
						.addComponent(lblEnterAmount)
						.addGap(18)
						.addComponent(textFieldAmount, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
						.addGap(55)
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
							.addComponent(panelEditors, 0, 0, Short.MAX_VALUE)
							.addComponent(panelNumbers, GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
						.addGap(34)
						.addComponent(btnBack, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
						.addGap(41))
			);
			setLayout(groupLayout);


	}
}
